<template>
  <div>
    <div class="table-box">
      <!-- 表格部分 -->
      <el-table :data="tableData" style="width: 100%" ref="table">
        <el-table-column
          prop="id"
          label="模板ID"
          min-width="100"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="模板名称"
          min-width="100"
          align="center"
        >
        </el-table-column>
        <!-- <el-table-column
          label="模板类型"
          prop="templateTypeDesc"
          min-width="100"
          align="center"
        >
        </el-table-column> -->
        <el-table-column
          prop="createdTime"
          label="创建时间"
          min-width="150"
          align="center"
        >
        </el-table-column>
        <el-table-column label="操作" min-width="100" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="toDetail(scope.row)">
              创建消息
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--分页-全局组件-->
    <pageCom
      :searchParams="searchParams"
      :total="total"
      @searchList="searchList"
    ></pageCom>
  </div>
</template>

<script>
import { filterImageMixins } from '@/mixins/filterImage'
import { templateList } from '@/api/notice'
import { packagingMethods } from './minix.js'
import { saveScrollMixins } from '@/mixins/saveScroll'
export default {
  mixins: [filterImageMixins, saveScrollMixins, packagingMethods],
  data() {
    return {
      tableData: [],
      total: 0,
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10 // 页面显示条数
      }
    }
  },
  created() {},
  mounted() {
    this.searchList()
  },
  methods: {
    toDetail(val) {
      if (val.messageTemplateAlias == 'PERIOD_OF_SERVICE_MESSAGE_TEMPLATE') {
        this.$router.push({
          name: 'wh:serverTemplate'
        })
      } else if (val.messageTemplateAlias == 'OPERATION_MESSAGE_TEMPLATE') {
        this.$router.push({
          name: 'wh:operationTemplate'
        })
      } else if (val.messageTemplateAlias == 'TARGETED_MESSAGE_TEMPLATE') {
        this.$router.push({
          name: 'wh:fixedMessage'
        })
      } else if (val.messageTemplateAlias == 'ACTIVITY_MESSAGE_TEMPLATE') {
        this.$router.push({
          name: 'wh:activityMessage'
        })
      }
    },
    /* 换页 */
    changePage(page) {
      this.searchParams.pageNum = page
      this.searchList()
    },
    /* 获取列表 */
    searchList() {
      let params = { type: 'OPERATION_TEMPLATE', ...this.searchParams }
      templateList(
        params,
        (res) => {
          this.total = res.total
          this.tableData = res.rows
          res.forEach((item) => {
            item.createdTime = this.resolvingDate(item.createdTime)
          })
        },
        (err) => {
          this.$message({
            message: err.message,
            type: 'warning'
          })
        }
      )
    }
  }
}
</script>

<style lang="scss" scoped></style>
